package com.lihh.rocket5.normal;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.io.UnsupportedEncodingException;

public class SingleQueueProducer {
  public static void main(String[] args) throws MQClientException, UnsupportedEncodingException, MQBrokerException, RemotingException, InterruptedException {
    // 建立 producer 实例
    DefaultMQProducer producer = new DefaultMQProducer("producer_group_001");
    // 设置 name server
    producer.setNamesrvAddr("localhost:9876");
    
    // 开启实例
    producer.start();
    
    for (int i = 0; i < 10; i++) {
      final String message = "hello single queue producer" + (i + 1);
      Message messageInstance = new Message("order004", message.getBytes(RemotingHelper.DEFAULT_CHARSET));
      SendResult result = producer.send(messageInstance);
      System.out.println(result);
    }
  }
}
